package day6;

/**
 * @author oldliu
 * @since 1.0
 */
public class BInsert {
    public static void main(String[] args) {
        int[] a = {21, 23, 212, 414, 734, 374, 74, 42, 18, 56, 88, 32, 23, 22, 21};
        for (int i = 1; i < a.length; i++) {
            int k = a[i];//0---i-1是有序的
            //k是新加入的值，保证加入后，0---i是有序的
            int j = i - 1;
            for (; j >= 0; j--) {
                if (a[j] < k) {
                    a[j + 1] = a[j];
                } else {
                    break;
                }
            }
            //找合适位置,和移动放一起
            a[j + 1] = k;
        }
 
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + "\t");
        }
        System.out.println();
    }
}
